package cn.sc.summer.adapter.controller;

import cn.hutool.core.lang.tree.Tree;
import cn.sc.summer.constant.model.Result;
import cn.sc.summer.domain.route.SysRouteService;
import cn.sc.summer.protocol.ValidatedGroup;
import cn.sc.summer.protocol.form.route.RouteBindForm;
import cn.sc.summer.protocol.form.route.RouteForm;
import cn.sc.summer.protocol.vo.route.RouteVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类名：路由管理
 *
 * @author a-xin
 * @date 2024/1/4 10:42
 */
@Slf4j
@RestController
@RequestMapping("/route")
@Api(tags = "route-路由管理")
public class SysRouteController {

    @Resource
    private SysRouteService sysRouteService;

    @PostMapping("/addRoute")
    @ApiOperation(value = "添加路由信息")
    public Result<RouteVO> addRoute(@Validated(ValidatedGroup.ADD_ROUTE.class) @RequestBody RouteForm form) {
        return Result.success(sysRouteService.addRoute(form));
    }

    @PostMapping("/updateRoute")
    @ApiOperation(value = "更新路由信息")
    public Result<RouteVO> updateRoute(@Validated(ValidatedGroup.UPDATE_ROUTE.class) @RequestBody RouteForm form) {
        return Result.success(sysRouteService.updateRoute(form));
    }

    @GetMapping("/deleteRoute")
    @ApiOperation(value = "删除路由信息")
    public Result<String> deleteRoute(@RequestParam("id") String id) {
        sysRouteService.deleteRoute(id);
        return Result.success();
    }

    @GetMapping("/getRoute")
    @ApiOperation(value = "获取路由信息")
    public Result<List<Tree<String>>> getRoute(@RequestParam(value = "id", required = false) String id) {
        return Result.success(sysRouteService.getRoute(id));
    }

    @PostMapping("/routeBindApi")
    @ApiOperation(value = "路由绑定api信息")
    public Result<String> routeBindApi(@RequestBody RouteBindForm form) {
        sysRouteService.routeBindApi(form);
        return Result.success();
    }

}
